package com.wodsy.phoenix.dataservice.base;

import com.wodsy.phoenix.datadao.base.IBaseDao;
import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;


public abstract class AbstractBaseService<M extends Serializable, PK extends Serializable> implements BaseService<M, PK>{
    protected  Logger logger = Logger.getLogger(this.getClass());

	protected abstract IBaseDao<M,PK> getIBaseDao();
	
	@Transactional
	public M get(PK pk){
		return getIBaseDao().get(pk);
	}
	@Transactional(rollbackFor=Exception.class)
	public void save(M obj){
		getIBaseDao().save(obj);
	}
	@Transactional(rollbackFor=Exception.class)
	public void update(M ojb){
		getIBaseDao().update(ojb);
	}
	@Transactional(rollbackFor=Exception.class)
	public void delete(M obj){
		getIBaseDao().delete(obj);
	}
	
	@Transactional(rollbackFor=Exception.class)
	public void saveOrUpdate(M obj){
		getIBaseDao().saveOrUpdate(obj);
	}
	
	@Transactional(readOnly=true)
	public List<M> findByAll(){
		return getIBaseDao().findByAll();
	}
	
	@Transactional(readOnly=true)
	public M findByProperty(String propertyName, Object value){
		return getIBaseDao().findByProperty(propertyName, value);
	}
	
	@Transactional(readOnly=true)
	public List<M> findAllByProperty(String propertyName,Object value){
		return getIBaseDao().findAllByProperty(propertyName, value);
	}
}
